const app=getApp();
var time = require('../../utils/util.js');
Page({
  data: {
    arrayList:[],
    n:'',
    imgList:[]
  },
  
  onLoad: function (options) {
    wx.request({
      url:`${app.globalData.url}/user/square`,
      dataType:'json',
      method:'GET',
      header:{
        "content-type":'application/json',
        authorization: wx.getStorageSync('token')
      },
      success:res=>{
          var arr=[];
          var arr1=[];
          console.log(res.data);
          var length=res.data.length;
          console.log(length);
          var name=wx.getStorageSync('userInfo').nickName;
          console.log(name);
          for(var i=0;i<length;i++){
            if(res.data[i].user_name==name){
              var date = new Date(parseInt(res.data[i].posts_time))
              res.data[i].posts_time=time.formatTime(date);
              arr.push(res.data[i]);
              res.data[i].posts_image= res.data[i].posts_image.split(',').filter(p=>p.length>0);
              arr1.push(res.data[i].posts_image);
              console.log(arr1)
              console.log(arr)
            }
          }
          this.setData({
            arrayList:arr,
            imgList:arr1
            // 将获取到的数据传给初始化的变量，在后端渲染
          })
          var n=this.data.arrayList.length;
          console.log(n);
          this.setData({n:n})
          // this.myspots();
      },
      fail(){
        console.log("no");
      }
    })
   
  }
})